package gaml.java;

import gaml.error.GamlException;
import gaml.yaml.YamlNode;
import gaml.yaml.ahchor.YamlAnchorCodeStore;
import gaml.yaml.ahchor.YamlAnchorObjectStore;


/**
 * implementing classes serializes none-dividable 
 * java types and classes into yaml strings
 * and deserializes them back
 * 
 * @author shnireck
 *
 * @param <T> serializing-deserializing object type
 */
public interface ClassSerializer <T> {
	public final static String ancestorNodeCode = "this";
	
	public Class <T> getObjectClass (); 

	/**
	 * yaml node for type T should not have yaml
	 * anchor and yaml anchors based processing for duplicate 
	 * object references should not be done for it
	 * @return true if node should not have anchor and 
	 * duplicate object references should not be processed, 
	 * otherwise false
	 */
	public boolean noAnchor ();
	
	/**
	 * yaml string from java object  of type T
	 * @param object java object of type T
	 * @param parent yaml node, parent to serializing one, 
	 * null if serializing top level object
	 * @return yaml string
	 */
	public YamlNode serialize (YamlNode node, T object, YamlAnchorObjectStore anchors) throws GamlException;
	
	/**
	 * java object of type T from yaml string 
	 * @param yaml valid yaml string
	 * @return java object of type T
	 */
	public T restore (YamlNode node, T object, YamlAnchorCodeStore anchors) throws GamlException;
	
	/**
	 * make new node for serializing into it
	 * @param parent node parent for this node
	 * @return new yaml node object
	 */
	public YamlNode createNode (YamlNode parent);
	
	/**
	 * instantate serializer's class
	 * to deserialize node into instantated object
	 * @throws GamlException can't create object instance
	 * @return
	 */
	public T createObject () throws GamlException;
}